package k2_oop.p9_collection.demo01;

import java.util.HashMap;
import java.util.TreeMap;

public class UseTreeMap {
    public static void main(String[] args) {

        TreeMap<String,String> treeMap = new TreeMap<>((m1,m2)->m2.length()-m1.length());

        treeMap.put("name","tom");
        treeMap.put("age","10");
        treeMap.put("gender","boy");

        System.out.println(treeMap);

//        HashMap<String,String> hashMap = new HashMap<>();
//        hashMap.put("name","tom");
//        hashMap.put("age","20");
//        hashMap.put("gender","boy");
//        System.out.println(hashMap);

        TreeMap<String,String> treeMap1 = new TreeMap<>(treeMap);

        treeMap1.put("addresss","北京");
        treeMap1.put("address11","北京");

        System.out.println(treeMap1);

        System.out.println(treeMap1.firstKey());
        System.out.println(treeMap1.lastKey());
        System.out.println(treeMap1.firstEntry());
        System.out.println(treeMap1.lastEntry());
        System.out.println(treeMap1.floorKey("1111111"));
        System.out.println(treeMap1.ceilingKey("1111111"));
        System.out.println(treeMap1.floorEntry("1111111"));
        System.out.println(treeMap1.ceilingEntry("1111111"));
        System.out.println(treeMap1.headMap("gender"));
        System.out.println(treeMap1.tailMap("gender",false));
        System.out.println(treeMap1.subMap("addresss",true,"name",true));


    }
}
